<template>

  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="shopmall"></Secondnav>
    </div>

    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
          <div class="layui-card-body">
            <fieldset class="layui-elem-field layui-field-title">
              <legend>商品分组列表</legend>
            </fieldset>
          </div>
          <!-- <div class="pagetop">
            <Search :seadate="searchArr"></Search>
          </div> -->
          <div class="layui-card-body">
            <div class="buttop">
              <button type="button" class="layui-btn  layui-btn-normal" @click="addData">新增分组</button>
              <!--  <button type="button" class="layui-btn" @click="getdate()">返回一级类别列表</button>-->
            </div>
            <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex"
              :fbtn="btn"></Tables>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>
<script>	
//	import echarts from 'echarts'
import Pagetop from '../../common/pagetop.vue'
import Secondnav from '../../common/secondnav.vue'
import Tables from '../../common/tables.vue'
import Search from '../../common/search.vue'
export default {
  name: 'wucshopgrouplist',
  components: { Pagetop, Secondnav, Tables, Search },
  data () {
    return {
      pdate: [], //表头  	
      res: "", //内容
      totalRows: "",//总数量
      curindex: 0, //页数
      btn: [],//按钮
      searchArr: [],//搜索
      isShow: false,
      seapram: '',
      type: 0,//判断是否是管理员-1
      shopId: localStorage.getItem("shopId"),
    }
  },
  mounted () {
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      //shopid传0是登陆的
      //  	if(pid){
      //  		var url="/category/getSubCategories";
      //			var dates={
      //				parentId:pid
      //			}
      //  	}
      //  	else{
      //var url="/category/treeJson"
      var url = "/mallcredit/bapi/v1.9/item-group/" + _this.shopId
      // if (_this.seapram) {
      //   var dates = {
      //     size: pageSize,
      //     page: _this.curindex,
      //     //sort:'createAt,DESC',
      //     //'status.equals':'ENABLE'
      //   };
      //   var res = _this.seapram;
      //   for (var i = 0; i < res.length; i++) {
      //     dates[res[i].key] = res[i].val;
      //   }
      // } else {
      //   var dates = {
      //     size: pageSize,
      //     page: _this.curindex,
      //     //sort:'createAt,DESC',
      //     //'status.equals':'ENABLE'
      //   };
      // }
      //	    }
      ajaxRequest(url, 'GET', 'json', "", function (ret, err) {
        var arr = [];
        arr[0] = [
          { field: 'id', title: 'ID' }
          , { field: 'groupName', title: '分组名称' }
          , {            field: 'activeStatus', title: '状态', templet: function (d) {
              if (d.activeStatus == "ENABLE") return "启用"
              else if (d.activeStatus == "DISABLE") return "禁用"
              else return "删除"
            }          }
          , {            field: 'right', title: '操作', width: '120', fixed: 'right', templet: function (d) {
              var str = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
              return str;
            }          }
        ];
        _this.pdate = arr;
        _this.res = ret.data;//res1;		  
        _this.totalRows = ret.data.length;
        _this.curindex = ret.data.pageNumber;
      })
    },
    getsearch: function () {
      var arr = [
        { field: 'groupName', title: '分组名称', type: 'input' }
      ];
      this.searchArr = arr;

    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();

    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = '';
      this.totalRows = '';
      this.curindex = "";
      this.getdate();
    },
    addData: function () {
      var _this = this;
      var data = {
        shopId: _this.shopId,
      }
      layer.open({
        type: 2
        , title: '新增分组'
        , content: baseurl + '/wucgoodsfzadd'
        , area: _this.screens() < 2 ? ['90%', '80%'] : ['500px', '500px']
      });
    },
    editInfo: function (data) {
      var _this = this;
      var data = {
        shopId: _this.shopId,
        id: data.id,
      }
      layer.open({
        type: 2
        , title: '编辑分组'
        , content: baseurl + '/wucgoodsfzadd'
        , area: _this.screens() < 2 ? ['90%', '80%'] : ['500px', '500px']
        , success: function (layero, index) {
          var iframeWin = window[layero.find('iframe')[0]['name']];
          iframeWin.getdates(data);
        },
      });
    },
    retailInfo: function (data) {
      /*新增子类*/
      var _this = this;
      layer.open({
        type: 2
        , title: '新增子类别'
        , content: baseurl + '/wucgoodsfladd?from=1'
        , area: _this.screens() < 2 ? ['90%', '80%'] : ['650px', '650px']
        , success: function (layero, index) {
          var iframeWin = window[layero.find('iframe')[0]['name']];
          iframeWin.getdates(data);
        },
      });
    },
    enableInfo: function (data) {
      var _this = this;
      var categoryId = data.id;
      var date = {
        categoryId: categoryId
      }
      var url = "/category/commodityStatusSubSet";
      ajaxRequest(url, 'GET', 'json', date, function (ret, err) {
        _this.getdate();
      })
    },
    upgradeInfo: function (data) {
      var _this = this;
      layer.open({
        type: 1
        , title: '输入推荐值'
        , content: '<div style="padding:30px;"><input  class="layui-input" name="tjz" value="" type="text"></div>'
        , btn: ['确定']
        , yes: function (index, layero) {
          var val = $('input[name=tjz]').val();
          if (val) {
            var url = "/category/recommendCategory";
            var date = {
              categoryId: data.id,
              parentId: data.categoryId,
              position: val
            }
            ajaxRequest(url, 'GET', 'json', date, function (ret, err) {
              layer.msg("操作成功")
              setTimeout(function () {
                _this.getdate();
                parent.layer.close(index);
              }, 2000)
            })

          }
          else {
            layer.msg("请输入推荐值")
          }
        }
      });
    },
    detailInfo: function (data) {

      this.getdate(data.id)
    },
    screens: function () {
      return screen();
    },
  },
  updated: function () {
    this.isShow = true;
    layui.use('form', function () {
      var form = layui.form;
      form.render();
    });
  },
}
</script>
<style scoped>
/**/
</style>
